<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>客户信息更新 - 管理后台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        body {
            min-height: 100vh;
            background: linear-gradient(135deg, #e0e7ff 0%, #f5f7fa 100%);
            font-family: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
            margin: 0;
        }

        .content-area {
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            padding: 40px 0;
        }

        .card {
            background: #fff;
            border-radius: 16px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.10);
            padding: 40px 36px 32px 36px;
            max-width: 420px;
            width: 100%;
        }

        .section-title {
            font-size: 22px;
            color: #1a3a6c;
            margin-bottom: 28px;
            padding-bottom: 12px;
            border-bottom: 2px solid #1a3a6c;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .section-title i {
            color: #1a3a6c;
            font-size: 22px;
        }

        .form-group {
            margin-bottom: 28px;
        }

        .form-group label {
            display: block;
            margin-bottom: 10px;
            font-weight: 600;
            color: #444;
            font-size: 16px;
        }

        .form-group input {
            width: 100%;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s;
        }

        .form-group input:focus {
            border-color: #1a3a6c;
            box-shadow: 0 0 0 3px rgba(26, 58, 108, 0.08);
            outline: none;
        }

        .btn-group {
            display: flex;
            gap: 18px;
            margin-top: 18px;
        }

        .btn-primary {
            flex: 1;
            padding: 15px;
            border-radius: 8px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            border: none;
            background: #1a3a6c;
            color: #fff;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            box-shadow: 0 2px 8px rgba(26, 58, 108, 0.10);
        }

        .btn-primary:hover {
            background: #15315a;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(26, 58, 108, 0.18);
        }

        .result-card {
            margin-top: 24px;
            background: #f8f9fa;
            border-left: 4px solid #1a3a6c;
            border-radius: 8px;
            padding: 18px 20px;
            font-size: 15px;
            color: #1a3a6c;
            box-shadow: 0 2px 8px rgba(26, 58, 108, 0.06);
            display: none;
            align-items: center;
            gap: 10px;
        }

        .result-card.success {
            border-left-color: #2ecc71;
            color: #2ecc71;
        }

        .result-card.error {
            border-left-color: #e74c3c;
            color: #e74c3c;
        }

        .result-card i {
            font-size: 18px;
        }
    </style>
</head>
<body>
    <div class="content-area">
        <div class="card">
            <div class="section-title">
                <i class="fa fa-user-edit"></i>客户信息更新
            </div>

            <div class="form-group">
                <label for="update-pid">证件号码</label>
                <input id="update-pid" type="text" placeholder="请输入证件号码">
            </div>

            <div class="form-group">
                <label for="update-name">客户姓名</label>
                <input id="update-name" type="text" placeholder="请输入客户姓名">
            </div>

            <div class="form-group">
                <label for="update-tel">手机号码</label>
                <input id="update-tel" type="text" placeholder="请输入手机号码">
            </div>

            <div class="form-group">
                <label for="update-addr">地址</label>
                <input id="update-addr" type="text" placeholder="请输入地址">
            </div>

            <div class="btn-group">
                <button class="btn-primary" onclick="updateUser()">
                    <i class="fa fa-check"></i>更新
                </button>
            </div>

            <div class="result-card" id="update-result">
                <i class="fa"></i>
                <span id="update-result-text"></span>
            </div>
        </div>
    </div>

    <script>
        function updateUser() {
            const data = {
                pid: document.getElementById('update-pid').value,
                customerName: document.getElementById('update-name').value,
                telephone: document.getElementById('update-tel').value,
                address: document.getElementById('update-addr').value
            };

            fetch('http://localhost:8080/admin/user/update', {
                method: 'PUT',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
            .then(response => response.json())
            .then(data => showUpdateResult(data))
            .catch(error => showUpdateResult({
                code: 'error',
                message: error.toString()
            }));
        }

        function showUpdateResult(result) {
            const card = document.getElementById('update-result');
            const textElement = document.getElementById('update-result-text');
            const iconElement = card.querySelector('i');

            if (result.code === '200') {
                card.className = 'result-card success';
                iconElement.className = 'fa fa-check-circle';
                textElement.innerText = '更新成功！';
            } else {
                card.className = 'result-card error';
                iconElement.className = 'fa fa-times-circle';
                textElement.innerText = result.message || '更新失败';
            }

            card.style.display = 'flex';
        }

        // 页面加载时检查URL参数并填充表单
        window.addEventListener('DOMContentLoaded', () => {
            const urlParams = new URLSearchParams(window.location.search);

            if (urlParams.has('pid')) {
                document.getElementById('update-pid').value = urlParams.get('pid');
            }
            if (urlParams.has('name')) {
                document.getElementById('update-name').value = urlParams.get('name');
            }
            if (urlParams.has('tel')) {
                document.getElementById('update-tel').value = urlParams.get('tel');
            }
            if (urlParams.has('addr')) {
                document.getElementById('update-addr').value = urlParams.get('addr');
            }
        });
    </script>
</body>
</html>